<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <script>
    let set = new Set();
    let set2 = new Set([1, 2, 3, 4, 5, 6, 7])
    console.log(set);
    console.log(set2);
    set2.add("admin")
    set2.add(2);//重复的不能重复
    set2.delete(2)//根据值删除
    set2.add(33).add(44).add(55).delete(44);//链式操作
    console.log(set2.has(44));
    // set2.clear()
    console.log(set2);

    console.log(set2.values());//获取值的集合(迭代器)


    //遍历1
    set2.forEach(function (value) {
      console.log(value);
    })
    //遍历2
    for (let value of set2) {
      console.log(value);
    }

    let [...arr] = set2;//set 转 数组
    console.log(arr);
    let s = new Set(arr);// 数组 转 set
    console.log(s);
  </script>
</body>

</html>